//
//  ViewController.m
//  09_UITableViewController
//
//  Created by dllo on 16/7/26.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, strong)NSMutableArray *arr;
@end

@implementation ViewController
- (NSMutableArray *)arr {
    if (!_arr) {
        self.arr = [NSMutableArray array];
    }
    return _arr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    NSArray *array = @[@"唐益梦", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪"];
    _arr = [NSMutableArray arrayWithArray:array];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"result"];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, 200)];
    view.backgroundColor = [UIColor redColor];
    //[self.view addSubview:view];
    // 系统刷新控件 UIRefreshControl
    // 注意, UIRefreshControl有自己的init方法
    // 系统默认:大小屏幕宽 60高
    self.refreshControl = [[UIRefreshControl alloc] init];
    // UIRefreshControl继承UIControl 可以绑定事件
    // 系统API注释中说明触发事件的枚举值 UIControlEventValueChanged
    [self.refreshControl addTarget:self action:@selector(refreshAction:) forControlEvents:UIControlEventValueChanged];
    // 注意: UITableViewController中self.view是tableView
    NSLog(@"%@", self.view);
}
// 刷新的方法
- (void)refreshAction:(UIRefreshControl *)refresh {
    // 延时操作
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新控件时结束刷新
        [self.refreshControl endRefreshing];
    });
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"result" forIndexPath:indexPath];
    cell.textLabel.text = _arr[indexPath.row];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

@end
